package com.zzptc.lxy.mybook;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.zzptc.lxy.mybook.Adapter.NoteAdapter;
import com.zzptc.lxy.mybook.Bean.Note;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import static org.litepal.LitePalApplication.getContext;

public class NoteActivity extends AppCompatActivity {
    private EditText edit_dialog;
    private ListView lv;
    private FloatingActionButton fab;
    private List<Note> noteList = new ArrayList<>();
    private NoteAdapter adapter;
    //这里 noteList 声明变量的时候就   直接实例化

    //    定义一个变量

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_note);
        initView();
        setListener();

    }

    private void setListener() {
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                创建一个视图
                final View v = LayoutInflater.from(NoteActivity.this).inflate(R.layout.popup, null);
                AlertDialog.Builder builder = new AlertDialog.Builder(NoteActivity.this)
                        .setView(v)
                        .setTitle("记笔记")
                        .setIcon(R.mipmap.pen)
                        .setNegativeButton("取消", null)
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {

                                SharedPreferences sp = getSharedPreferences("userinfo", MODE_PRIVATE);

                                SharedPreferences.Editor editor = sp.edit();

                                Note n = new Note();// 无参
                                n.setId(0);//id
                                n.setBookimg(sp.getInt("bookimg", -1));//书图片
                                n.setBookname(sp.getString("bookname", ""));//书名
                                n.setNotetxt(edit_dialog.getText().toString()); //内容

                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");/*设置时间格式*/

                                String newdata = sdf.format(n.getTime());


                            }

                        });
                builder.create().show();

            }
        });


    }

    private void initView() {
//        lv = findViewById(R.id.lv);
        fab = findViewById(R.id.fab);
        edit_dialog = findViewById(R.id.edit_dialog);

//  有参方法
//
//        Note n1 = new Note(0, R.mipmap.dune, "沙丘", "沙丘真的是神作啊", "2020");
//        noteList.add(n1);
//
//        adapter = new NoteAdapter(NoteActivity.this, R.layout.note_cell, noteList);
//        lv.setAdapter(adapter);
    }
}